#ifndef __H_GAME_H__
#define __H_GAME_H__

#include <deque>
#include <vector>
#include <map>
#include "ICC_Timer_Handler.h"
#include "RedisClient.h"
#include "GameBase.h"
#include "DbPart.h"
#include "CClient.h"
#include "def.h"
#include "HostBase.h"

using namespace std;

// http server
#include "handler.h"
#include "http.h"
#include "buffer.h"
#include "listener.h"
#include "mainworker.h"
#include "msgrouter.h"


class CHost;
class CGameServer :public BYTimerOject
{
public:
	CGameServer();
	virtual ~CGameServer();
public:
	virtual bool InitGame();
	virtual int OnBYTimeOut(int Timerid);
	int ProcessPacket(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int ProcEventBackConn(int ev_id, SpiderEvent* pEvent);
	int ProcEventBackClose(int ev_id, SpiderEvent* pEvent);
	int ProcEventClientClose(int ev_id, SpiderEvent* pEvent);
	int ProcGameInit(int ev_id, SpiderEvent* pEvent);
	int SendToSrvNew(NETInputPacket* pack);
private:
    int HandleRefreshConfig(SocketHandler* pHandler, NETInputPacket* inputPkg);
    int HandleVerifyRank(SocketHandler* pHandler, NETInputPacket* inputPkg);

    int ProPHPPack(SocketHandler* pHandler, NETInputPacket* inputPkg);
    int ProcSrvPack(SocketHandler* pHandler, NETInputPacket* inputPkg);
	int srvtypeModSend(unsigned short stype, unsigned int mod, CCPacketBase* pack);
	int srvtypeRandSend(unsigned short stype, NETInputPacket* pack);
	int sendToPHP(SocketHandler* pHandler, NETInputPacket* pack);
	int sendToSrv(SocketHandler* pHandler, NETInputPacket* pack);
	
	int sendToOneSrv(unsigned short stype, unsigned int sid, NETInputPacket* pack);
	void ProcHeartBeat(SocketHandler* pHandler, NETInputPacket* inputPkg);
	bool ReadCommonConf(const char* strxml);
	map<unsigned short, map<unsigned int, CClient*> > m_node;
	map<unsigned short, vector<unsigned int> > m_nodeId;
public:
    
	CHost* m_pHost;
	CClient* m_cliPhp;
	ServerConf m_phpCfg;
	std::string m_phpPostUrl;
	int m_httpListenPort;
};


#endif


